package data.platform.common.merge;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalDateTime;

@Getter
@Setter
@NoArgsConstructor
public class IfCrowdTimeAggregateItem extends AggregateItem {

    private Double ifCrowdTimePercentThreshold;

    private Integer crowdCount = 0;

    private Integer count = 0;

    public IfCrowdTimeAggregateItem(MergePeriod mergePeriod, MergeTimeWindow mergeTimeWindow, Double ifCrowdTimePercentThreshold) {
        super(mergePeriod, mergeTimeWindow);
        this.ifCrowdTimePercentThreshold = ifCrowdTimePercentThreshold;
    }

    @Override
    public void compute(Double value, LocalDateTime eventTime) {
        if (value > ifCrowdTimePercentThreshold) {
            crowdCount++;
        }
        count++;

        dirty.compareAndSet(false, true);
    }
}
